package com.health.mapp.impl;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.health.db.model.EPayCashPayment;
import com.health.db.service.sm.IWXPayService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.WXTestReq;
import com.health.mapp.interImpl.PayActionServerImpl;
import com.health.mapp.service.SecureUtil;
import com.health.mapp.utils.Constant;
import com.health.mapp.utils.Response;
import com.health.pay.tencent.protocol.transfers.TransfersReq;

public class WXTestImpl implements ActionInterface{
	
	private static Logger logger=Logger.getLogger(WXTestImpl.class);
	
	@Autowired
	private IWXPayService wXPayService;
	
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		// TODO Auto-generated method stub
	
		/* String remoteIP=SecureUtil.getRemoteHost((HttpServletRequest) header.getHttpRequest());
		
		TransfersReq transfersReq = new TransfersReq
				( "测试", "20180511120000", "oo6sW0dHp9-STvq0l5B7EM3adb7c", 100, "测试", remoteIP);
		wXPayService.transfers(transfersReq);*/
		
		
		/*int fee = ePayCashPayment.getPaycashTotal().multiply(new BigDecimal(100)).intValue();
		RefundReqData refundReqData = new RefundReqData(
				ePayCashPayment.getBankCashIdno(), ePayCashPayment.getPaycashIdno(), null,
				ePayCashPayment.getPaycashIdno(),fee,fee, null, null);
		RefundResData refundResData = wXPayService.refund(refundReqData);*/
		
		//115367-8-41
		
		//1000130529-457-61
		//1000130530-458-61
		
		
		WXTestReq req = (WXTestReq) reqBean;
		
		//String out_trade_no = "1000130529-457-61";
		String out_trade_no = "131311-904-61";
		
		String total_amount= "36000";
		EPayCashPayment payment = new EPayCashPayment();
		
		payment.setBankCashIdno("BBBBBBBBBBB");
		payment.setPaycashTotal(new BigDecimal(total_amount)); 
		
		PayActionServerImpl impl = new PayActionServerImpl();
		impl.updatePayCashPaymentLog(out_trade_no, payment);
		
		try {
			impl.payAction(out_trade_no, Constant.CONSTANTS_PAYMENT_WEIXIN);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}


	public IWXPayService getwXPayService() {
		return wXPayService;
	}


	public void setwXPayService(IWXPayService wXPayService) {
		this.wXPayService = wXPayService;
	}
}
